<template>
  <div>
    <el-form
      ref="form"
      :rules="rules"
      :model="form"
      label-width="120px"
      label-position="left"
    >
      <el-form-item label="会员ID:" prop="user_id">
        <el-select
          v-model="form.user_id"
          style="width: 100%"
          placeholder="请选择会员ID"
        >
          <el-option
            v-for="(item, index) in userlist"
            :key="index"
            :label="item.user_login"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="isadd"  label="类型:" prop="status">
        <el-radio-group v-model="status">
          <el-radio :label="1">充值</el-radio>
          <!-- <el-radio :label="0">扣款</el-radio> -->
        </el-radio-group>
      </el-form-item>
      <el-form-item label="金额:" prop="coin">
        <el-input v-model="form.coin" type="number" placeholder="请输入金额"></el-input>
      </el-form-item>
      <!-- <el-form-item label="变更前余额:" prop="money">
        <el-input v-model="form.money" type="number" placeholder="请输入变更前余额"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="变更后余额:" prop="money">
        <el-input v-model="form.money" type="number" placeholder="请输入变更后余额"></el-input>
      </el-form-item> -->
      <el-form-item label="商品:" prop="msg">
        <el-input v-model="form.msg" placeholder="请输入商品"></el-input>
      </el-form-item>
      <el-form-item label="资金流水单号:" prop="order">
        <el-input v-model="form.order" placeholder="请输入资金流水单号"></el-input>
      </el-form-item>
    </el-form>
    <div class="flexend">
      <el-button type="primary" @click="onSubmit">确 认</el-button>
      <el-button @click="handleClose">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { validPhone } from "@/utils/validate";
import { rechargeCoin } from '@/api/pay';
export default {
  data() {
    return {
      status:1,
      userlist: [],
      form: {
        id: undefined,
        user_id:'',
        coin: "",
        msg: "",
        order: "",
        // status: 1,
      },
      rules: {
        user_id: [
          { required: true, message: "请选择会员", trigger: "change" }
        ],
        coin: [{ required: true, message: "请输入金额", trigger: "blur" }],
        msg: [{ required: true, message: "请输入商品", trigger: "blur" }],
        order: [
          { required: true, message: "请输入资金流水单号", trigger: "blur" },
        ],
        // status: [{ required: true, message: "请选择状态", trigger: "change" }],
      },
    };
  },
  props:{
    isadd:{
       type:Boolean,
       default:true
    }
  },
  created(){
    this.getDicts('/manage/index/userList').then(res=>{
      this.userlist = res.data
    })
  },
  methods: {
    onSubmit() {
      this.$refs.form.validate((valid) => {
        if (!valid) return;
        rechargeCoin(this.form).then(res=>{
          this.$message.success('充值成功')
          this.$emit('close',1)
        })
      });
    },

    resetForm() {
      this.$refs.form.resetFields();
    },

    handleClose(){
        this.$emit('close')
    }
  },
};
</script>